﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Abigail.Ui.Article.StockLoc
{
    public partial class UiEditStockLocationArea : Form
    {
        private Controller c;
        private bool isCreatingNew = false;

        //Create new
        public UiEditStockLocationArea(Controller c)
        {
            InitializeComponent();
            this.Text = "Nytt lagerområde";
            this.c = c;
            isCreatingNew = true;
            this.Show();
        }

        public UiEditStockLocationArea(Controller c, string areaCode, string definition)
        {
            InitializeComponent();
            isCreatingNew = false;
            this.c = c;

            txt_areaCode.Text = areaCode;
            txt_areaCode.Enabled = false;
            txt_definition.Text = definition;

            this.Show();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (isCreatingNew)
            {
                c.SaveNewStockLocationArea(txt_areaCode.Text, txt_definition.Text, this);
            }
            else
                c.UpdateStockLocationArea(txt_areaCode.Text, txt_definition.Text, this);

        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            Popup.FunctionNotImplemented();
        }
    }
}
